package com.bnuboy.activity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.bnuboy.adapter.ListViewContentAdapter;
import com.bnuboy.baidumap.MapDemo;

public class MainActivity extends FragmentActivity   {
	private ImageView img;
	private ListView listView;
	private Button baidumapButton;
	private Fragment[] mFragments;  
    private RadioGroup bottomRg;  
    private FragmentManager fragmentManager;  
    private FragmentTransaction fragmentTransaction;  
    private RadioButton rbOne, rbTwo, rbThree, rbFour; 
	private void init(){
		mFragments = new Fragment[3];  
        fragmentManager = getSupportFragmentManager();  
        mFragments[0] = fragmentManager.findFragmentById(R.id.fragement_main);  
        mFragments[1] = fragmentManager.findFragmentById(R.id.fragement_search);  
        mFragments[2] = fragmentManager.findFragmentById(R.id.fragement_setting);  
        fragmentTransaction = fragmentManager.beginTransaction().hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2]);  
        fragmentTransaction.show(mFragments[0]).commit();  
        setFragmentIndicator();  
	}
	private void setFragmentIndicator() {  
		  
        bottomRg = (RadioGroup) findViewById(R.id.bottomRg);  
        rbOne = (RadioButton) findViewById(R.id.rbOne);  
        rbTwo = (RadioButton) findViewById(R.id.rbTwo);  
        rbThree = (RadioButton) findViewById(R.id.rbThree);  
  
        bottomRg.setOnCheckedChangeListener(new OnCheckedChangeListener() {  
  
            @Override  
            public void onCheckedChanged(RadioGroup group, int checkedId) {  
                fragmentTransaction = fragmentManager.beginTransaction()  
                        .hide(mFragments[0]).hide(mFragments[1])  
                        .hide(mFragments[2]);  
                switch (checkedId) {  
                case R.id.rbOne:  
                    fragmentTransaction.show(mFragments[0]).commit();  
                    break;  
  
                case R.id.rbTwo:  
                    fragmentTransaction.show(mFragments[1]).commit();  
                    break;  
  
                case R.id.rbThree:  
                    fragmentTransaction.show(mFragments[2]).commit();  
                    break;  
  
                default:  
                    break;  
                }  
            }  
        });  
    } 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		this.init();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
